
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title></title>
    <meta name="format-detection" content="telephone=no">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <link rel="stylesheet" type="text/css" href="css/reset.css">
    <link rel="stylesheet" type="text/css" href="css/layer.css">
    <link rel="stylesheet" type="text/css" href="css/swiper.min.css">
    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" type="text/css" href="css/index.css">
    <script src="js/jquery.min.js"></script>
    <script type="text/javascript" src="js/jquery.cookie.js"></script>
    <script src="js/layer.js"></script>
    <script src="js/swiper.min.js"></script>
    <script type="text/javascript" src="js/common.js"></script>
</head>
<body>
<div class="nav"></div>
<div class="film-detail top125">
	<div class="detail-top">
	</div>
	<div class="list">
        <div class="list-type clearfix">
          <div class="list-title">剧情简介</div>
        </div>
        <div class="details-plot">
    
        </div>
    </div>
    <div class="list">
        <div class="list-type clearfix">
          <div class="list-title">电影推荐</div>
          <a href="film_list.html" class="list-clone">更多 <span></span></a>
        </div>
        <ul>
        </ul>
    </div>
    <!-- 支付 -->
    <div class="choose-pay-way choose-hide">
    	<div class="choose-box">
    		<div class="choose-top clearfix">
		    	<div class="choose-title">选择支付方式</div>
		    	<div class="close-choose">取消</div>
	    	</div>
	    	<div class="choose-list">
	    		<ul>
	    			<li data-id="01">
	    				<a href="javascript:;" data-id="01" class="change-way">
	    					<span><img src="images/yue@2x.png"></span>
	    					<span>余额</span>
	    					<span class="choose-list-money">￥00.00</span>
	    				</a>
	    				<a href="record.html?tag=ye" class="goto-chongzhi">充值</a>
	    			</li>
	    			<li data-id="02">
	    				<a href="javascript:;" data-id="02" class="change-way">
	    					<span><img src="images/zfbpay@2x.png"></span>
	    					<span>支付宝</span>
	    				</a>
	    			</li>
	    			<li data-id="03">
	    				<a href="javascript:;" data-id="03" class="change-way">
	    					<span><img src="images/wxpay@2x.png"></span>
	    					<span>微信</span>
	    				</a>
	    			</li>
	    		</ul>
	    		<div class="pay-tips">*付款会有几分钱浮动属正常，请放心支付</div>
	    	</div>
    	</div>
    </div>
</div>
<div class="search-box searchide"></div>
<script type="text/javascript">
	$(function(){
		// 显示错误信息弹框
		var url = window.location.href;
		var domain = window.location.host;
	    function layerMsg(msg){
	        layer.open({
	            content: msg,
	            style: 'background-color:rgba(0,0,0,1); color:#fff; border:none;',
	            time: 3
	        }); 
	    }
		function getQueryString(name) {
	        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
	        var r = window.location.search.substr(1).match(reg);
	        if (r != null) return (r[2]);
	        return null;
	    }
        var id = getQueryString('id');
        var uid = $.cookie('id');
        var token = $.cookie('token_access');
		$.ajax({
			url: window.baseUrl+'api/movie/details',
			type: 'get',
			data:{
				id : id,
			},
			beforeSend: function (XMLHttpRequest) {
         		XMLHttpRequest.setRequestHeader("token", $.cookie('token_access'));
            },
			success: function (data) {
			  	var details = '';
			  	var data = data.datas;
			  	if(data.isPurchased == '00'){
			  		var price = data.price;
			  		details = details + '<div class="detail-img">';
				  	details = details + '<img src="'+data.logo+'"></div><div class="detail-info">';
				  	details = details + '<div class="detail-title"><span>'+data.movieName+'</span><span>('+data.year+')</span></div>';
					// details = details + '<div class="detail-category">类别：<span>'+data.category+'</span></div>';
					details = details + '<div class="detail-category">类别：<span>电影</span></div>';
					details = details + '<div class="detail-address">地区：<span>'+data.area+'</span></div>';
					details = details + '<div class="detail-type">类型：<span>'+data.type+'</span></div>';
					details = details + '<div class="play-type">'+data.price+'元 观看</div></div>';
			  	}else{
			  		if(data.isExpire =='00'){
			  			details = details + '<div class="detail-img">';
					  	details = details + '<img src="'+data.logo+'"></div><div class="detail-info">';
					  	details = details + '<div class="detail-title"><span>'+data.movieName+'</span><span>('+data.year+')</span></div>';
						details = details + '<div class="detail-category">类别：<span>电影</span></div>';
						details = details + '<div class="detail-address">地区：<span>'+data.area+'</span></div>';
						details = details + '<div class="detail-type">类型：<span>'+data.type+'</span></div>';
						details = details + '<a class="play-type" href="video.html?id='+id+' ">立即观看</a>';
						details = details + '<div class="sy-time">到期时间：<span>'+data.expireTime+'<span></div></div>';
			  		}else{
			  			layerMsg('电影已过期，请重新购买观看！');
			  		}
			  		
			  	}
				$(".detail-top").append(details);
				$(".details-plot").append(data.content);
				// 点击红色的支付按钮选择支付方式
				$("div.play-type").off().on("click",function(){
					if($.cookie('token_access') == undefined){
						window.location.href="login.html?url="+url;
					}else{
						$.ajax({
							url: window.baseUrl+'api/user/info',
							type: 'get',
							data:{
								id : uid,
							},
							beforeSend: function (XMLHttpRequest) {
				         		XMLHttpRequest.setRequestHeader("token", $.cookie('token_access'));
				            },
							success: function (result) {
							// 个人中心列表
								if(result.code == 200){
									$(".choose-list-money").html(result.datas.customer.balance+"元")
								}else{
									window.location.href="login.html?url="+url;
								}
								
							}
				        });
						if(data.isPurchased == '00'){
							$(".choose-pay-way").removeClass('choose-hide');
						}
						var paymentset = true;
						$(".choose-list li").on("click",function(){
							// 支付
							var payType = $(this).find('.change-way').attr('data-id');
							$.ajax({
						        url:window.baseUrl+'api/order/createOrder',
						        type:'Post',
						        dataType:'json',
						        data:{
						            price:price,
						            payType:payType,
						            movieId:id,
						            returnUrl:url,
						            url:domain
						        },
						        beforeSend: function (XMLHttpRequest) {
					         		XMLHttpRequest.setRequestHeader("token", $.cookie('token_access'));
					            },
						        success:function(data){ 
						            var code = data.code;
						            if(code === '200'){
						                if(payType == '01'){
						                	if(paymentset){
						                		paymentset = false;
						                		var orderNum = data.datas;
							                	$.ajax({
											        url:window.baseUrl+'api/order/balancePayment',
											        type:'Post',
											        dataType:'json',
											        data:{
											            orderNum : orderNum
											        },
											         beforeSend: function (XMLHttpRequest) {
										         		XMLHttpRequest.setRequestHeader("token", $.cookie('token_access'));
										            },
											        success:function(data){ 
											            if(data.code == '200'){
											            	layerMsg('支付成功');
											            	setTimeout(function(){
											            		location.reload() 
											            	},1000)
											            }else{
											            	layerMsg('账户余额不足请充值');
											            	paymentset = true;
											            }
											        }
											    })
						                	}
						                }else{
						                	var istype = data.datas.istype;
							                var notify_url = data.datas.notify_url;
							                var orderid = data.datas.orderid;
							                var price = data.datas.price;
							                var return_url = data.datas.return_url;
							                var key = data.datas.key;
							                uid = data.datas.uid;
							                // 用表单post的方式，post参数并跳转到此网址，显示我们的支付页。
							                function postForm(URL, PARAMS){   
											    var temp = document.createElement("form");        
											    temp.action = URL;        
											    temp.method = "post";
											    // temp.target = "_blank"; 
											    temp.style.display = "none";        
											    for (var x in PARAMS) {        
											        var opt = document.createElement("textarea");        
											        opt.name = x; 
											        opt.value = PARAMS[x];      
											        temp.appendChild(opt);        
											    }        
											    document.body.appendChild(temp);        
											    temp.submit();        
											    return temp;        
											}
											postForm('https://pay.bbbapi.com/', {
									            istype : istype,
									            notify_url : notify_url,
									            orderid : orderid,
									            price : price,
									            return_url: return_url,
									            key: key,
									            uid:uid
										    })
						                }
						            }else{
						            	layerMsg(data.message);
						            }
						        }
						    })
						})
					}	
				})
				// 点击立即播放的时候新增播放历史
				// $("a.play-type").on("click",function(){
				// 	$.ajax({
				// 		url: window.baseUrl+'api/movie/addViewHistory',
				// 		type: 'get',
				// 		data:{
				// 			movieId : id,
				// 		},
				// 		beforeSend: function (XMLHttpRequest) {
			 //         		XMLHttpRequest.setRequestHeader("token", $.cookie('token_access'));
			 //            },
				// 		success: function (data) {
				// 		}
			 //        });
				// })
				$(".close-choose").on("click",function(){
					$(".choose-pay-way").addClass('choose-hide');
				})

			}
		});
		// 电影推荐列表
		$.ajax({
			url: window.baseUrl+'api/movie/recommendList',
			type: 'get',
			success: function (data) {
			  	var details_tj = '';
			  	var result = data.datas.result;
			  	for(var i = 0;i<result.length;i++){
			  		if(result[i].tag == ''){
                        var setTag = ''
                    }else{
                        var setTag = '<div class="hot"><span>'+result[i].tag+'</span></div>'
                    }
                    details_tj = details_tj+'<li><div class="piclist-img">'+
                    '<a href="detail.html?id='+result[i].id+'" >'+
                    '<img src="'+result[i].logo+'" alt="">'+
                    '<div class="definition">'+result[i].clarity+'</div>'+setTag+
                    ' </a></div><div class="piclist-title">'+result[i].movieName+'</div></li></div>';
                }
                $(".film-detail .list ul").append(details_tj)
			}
		});
	})
	
</script>
</body>
</html>